package roborally.model.executables.commands;

import roborally.model.*;
import roborally.model.executables.RobotCommand;
/**
 * RobotCommand that turns the robot clockwise or counterclockwise if it has energy to do so.
 */
public class Turn extends RobotCommand{
	private final boolean clockwise;
	public boolean isClockwise() { return clockwise; }
	/**
	 * @param 	clockwise
	 * 			A boolean indicating if the robot should turn clockwise or counterclockwise.
	 */
	public Turn(Robot robot, Program program, boolean clockwise) {
		super(robot, program);
		this.clockwise = clockwise;
	}
	/**
	 * @effect if the robot has sufficient energy to turn, it will turn as specified by isClockwise()
	 */
	@Override
	public void executeCommand() {
		if(getRobot().hasEnergyToTurn())
			getRobot().turn(isClockwise());
	}
	
	@Override
	public String toString(){
		if(isClockwise()) return "turn clockwise";
		else return "turn counterclockwise";
	}
	
}
